ostree-pull: Fix segfault by initializing pull_data earlier
authorAdrian Perez <aperez@igalia.com>
Wed, 9 May 2012 15:49:03 +0000 (18:49 +0300)
committerColin Walters <walters@verbum.org>
Wed, 9 May 2012 18:10:23 +0000 (14:10 -0400)
In the case of not being able to check the repository or not being able
to parse command line arguments, attributes from "pull_data" would be used
with garbage in them. This patch makes initialization of the sctructure to
happen earlier so it is safe to use in those cases.

src/ostree/ostree-pull.c

index 976f36ae4b9a2f18d529a2bebe2f2964fdf5f4a5..00c63afe2c63818fbe9567604d4a671beee3e9e7 100644 (file)
@@ -1087,6 +1087,8 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   GKeyFile *config = NULL;
   char **configured_branches = NULL;
 
+  memset (pull_data, 0, sizeof (*pull_data));
+
   context = g_option_context_new ("REMOTE [BRANCH...] - Download data from remote repository");
   g_option_context_add_main_entries (context, options, NULL);
 
@@ -1097,7 +1099,6 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   if (!ostree_repo_check (repo, error))
     goto out;
 
-  memset (pull_data, 0, sizeof (*pull_data));
   pull_data->repo = repo;
   pull_data->file_checksums_to_fetch = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);